var USER_INFO = null;	//用户基本信息

var Core = {};

//配置信息
Core.CONFIG = {
	IsLogin: false, //是否已经登陆
	Main: "#main",
	DefaultTitle: "我的云盘",
	MinStatus: "#min_status",
	StockStatus: "#stock_status",
	ActiveClass: "window-current",
	WindowMinWidth: 400,
	WindowMinHeight: 300,
	UpEngine: 0,	//0 为Flash上传 1 为ActiveX上传
	FUpImg: PAGE_PATHS["MY"]+"/statics/web/swfup/v4_up_btn.png?v=2",	//Flash上传按钮图片地址
	FUpSWF: PAGE_PATHS["MY"]+"/statics/web/swfup/swfup.swf",	//Flash上传swf路径
	FUpDebug: false,	//Flash上传调试开关
	FUpErrMsg: {
		"-100":"文件数量已超限制",
		"-110":"大小不能超过%1",
		"-120":"不能上传空文件",
		"-130":"无效的文件类型",
		"-200":"网络不正常，上传中断",
		"-210":"上传地址丢失",
		"-220":"网络异常",
		"-230":"不安全的上传",
		"-240":"上传限制超标",
		"-250":"上传失败",
		"-260":"未找到指定的文件",
		"-270":"文件验证失败",
		"-280":"文件列队取消",
		"-290":"上传已停止",
		"-300":"服务器异常"
    },	//flash 上传错误信息
    
    Path: {
		My: PAGE_PATHS["MY"],
		MyAjax: PAGE_PATHS["MY"],
		HOME: PAGE_PATHS["HOME"] + "/",
		G: PAGE_PATHS["Q"] + "/",
		GAJAX: PAGE_PATHS["Q"] + "/",
		U: PAGE_PATHS["U"] + "/",
		PASS: PAGE_PATHS["PASSPORT"] + "/",
		Msg: PAGE_PATHS["MSG"] + "/",
		OS: PAGE_PATHS["U"] + "/",
        VIP: PAGE_PATHS["VIP"],
        VIP_ORDER: PAGE_PATHS["VIP"] + "/vip"
	},
    
    TUpCodeBase_NB: PAGE_PATHS["U"] + "/statics/web/install/upload_v1.5.6.6.cab",
	TUpDownloadUrl_np: PAGE_PATHS["U"] + "/statics/web/install/upload_v1.5.6.6.exe",
    TUpDownloadUrl_np_mac: PAGE_PATHS["U"] + "/statics/web/install/upload_v1.5.6.5.dmg",
    TUpDownloadUrl_np_unix: PAGE_PATHS["U"] + "/statics/web/install/upload_v1.5.6.5_x64.tar.gz",
    TUpDownloadUrl_np_unix_32: PAGE_PATHS["U"] + "/statics/web/install/upload_v1.5.6.5_x86.tar.gz",

    TUpClassID_NB:"clsid:CC98CADB-E94C-4240-9723-3E0707271E17",
	TUpSp:'0',
	TUpDomId:"js_ocx_control_object",
	TUpFFVersion: "Ylmf Upload Plug-in v1.5.6.6",     //Windows版本号
    TUpMacVersion: "Ylmf Upload Plug-in v1.5.6.5",   //Mac版本号
    TUpUnixVersion: "Ylmf Upload Plug-in v1.5.6.5", //Unix版本号
    TUpTestVersion: {}, //测试版版本号
	TUploadServer: "",	//上传调度服务器
	TDeleteServer: "",	//上传删除文件服务器
	TSelectCount: 20,   //每次选择文件的数量限制
	TUpRefashFreq: 50,  //更新文件状态的毫秒数
    TUpIsProxy: 0,  //是否使用代理上传
    TUpReTryCount:15,    //重试次数
    TUpSleepTime:2, //下一次重试时间间隔
    
	OpenUpDir: [1,2,3,4,5,9],   //打开上传的目录
    
	TypeStruct:{
		"0":"临时空间",
		"1":"我的文件",
		"2":"我的文档",
		"3":"我的相册",
		"4":"我的音乐",
        "5":"附件通",
        "9": "我的视频"
	},
	ICOType:{	//图标类型
		"1_0":"ico-file",
		"2_0":"ico-document",
		"3_0":"ico-photo",
		"4_0":"ico-music",
		"9_0":"ico-video",
        "5_0":"ico-file",
		"21_0":"ico-folder",
		"22_0":"ico-sync",
		"-2_0": "ico-transfer",
		share:"ico-shared-folder",
		Default:"ico-folder"
    },
	FileICOMod: 0,	//操作图标默认显示模式 0 小图标 1 大图标
	FileListMod: "view",	//默认
	FileDownload: "#js_download_list_box",
	
	MusicPlay: "#js_jplay_box",

	JSPath:{
		FUp: PAGE_PATHS["MY"]+"/statics/web/swfup/swfup_min.js",	//swfupload js URI
		JPlayer: PAGE_PATHS["MY"]+"/statics/web/js/jquery.jplayer.min.js?v=2012",	//Jplayer js URI
		JPProxy: PAGE_PATHS["MY"]+"/statics/web/js/jplayer_proxy.js?v=11"	//Jplayer proxy js URI
		
	},
	StaticServer: "/",
	ServerNum: [0,1,2,3,4,5,6,7,8,9],
	SWFPath: {
		PhotoView: PAGE_PATHS["MY"]+"/statics/web/photo/v3/YViewer.swf",
        SWF_LoadImg: PAGE_PATHS["MY"] + "/statics/web/photo/v3/loading.gif",
		Warn: PAGE_PATHS["MY"]+"/statics/web/warn/warn.swf"
	},
	CssPath:{
		Play:  PAGE_PATHS["MY"]+"/statics/web/css/player.css?v=6"
	},
	
	EditPath:PAGE_PATHS["MY"]+"/statics/web/editor/editor.php?charset=utf-8&allowhtml=1&domain=" + encodeURIComponent(""),	//描述编辑框URI
	EditTextArea: "js_ttHtmlEditor",	//描述编辑框TextArea id

	TwinkTime: 70,	//提示框闪烁时长
	TwinkCount: 3,	//提示框闪烁次数
	MsgTimeout: 2000,	//minmessage 自动隐藏时间
	
	IsWindows: true,    //需要更换被占用，判断是否是windows 改为 IsWindowNT
    IsWindowNT: (navigator.userAgent.indexOf("Windows NT")!=-1),
    IsMac: (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel"),
	WinRightPX: 12,
    Reader: {
        URL: PAGE_PATHS["MY"]+"/statics/web/paper/FP.swf?v=2.0",
        ID: "js_flash_reader_main"
    },
	DebugKey: false,	//调试开关
    TUpDebugKey: false,
    TUpDebugTime: 0
}

Core.FileConfig = {
    aid: -1,
    cid: -1,
    DataAPI: false
}

Core.Server = {
	Index: 0,
	GetStatic: function(){
		var result = String.format(Core.CONFIG.StaticServer,Core.Server.Index);
		Core.Server.Index++;
		if(Core.Server.Index > 9){
			Core.Server.Index = 0;
		}
		return result;
	}
}

Core.ACTIVE = {
	AcDesk: 0,
	GetMain: function(){
        return $(document.body);
	}
}

Core.Setting = {
	Change: function(r, callback){
		var data = {}
		for(var k in r){
			data['key[' + k + ']'] = r[k];
		}
		$.ajax({
			url: "?ct=ajax_user&ac=set_user_config",
			type: "POST",
			dataType: "json",
			data: data,
			success: function(res){
				if(res.state){
					if(Core.CONFIG.IsWindows){
						if(r["os_file_upload_type"] != undefined){
							if(r["os_file_upload_type"] == 0){
								Core.CONFIG.UpEngine = 0;
							}
							else{
								Core.CONFIG.UpEngine = 1;
								if(r["os_file_upload_type"] == 1){
									Core.CONFIG.TUpSp = "0";
								}
								else{
									Core.CONFIG.TUpSp = "1";
								}
							}
						}
					}
					else{
						Core.CONFIG.UpEngine = 0;
					}
				}
				if(callback){
					callback(res);
				}
			}
		})
	}
}

Core.Parse = {
	Html: function(dom){
		//解析自定标签属性
	},
	Code: function(name,type){
		//解析Javascript
		var obj = eval(name);
	}
}

Core.Html = {
	GetShadow: function(){
        return '';
		return '<div class="shadow-cor cor-tl"></div><div class="shadow-cor cor-tr"></div><div class="shadow-cor cor-br"></div><div class="shadow-cor cor-bl"></div><div class="shadow-cor cor-t"></div><div class="shadow-cor cor-r"></div><div class="shadow-cor cor-b"></div><div class="shadow-cor cor-l"></div>';
	},
	StopPropagation:function(e){
		if($.browser.msie){
            event.cancelBubble=true;
		}else{
			e.stopPropagation();
			e.preventDefault();
		}	//停止冒泡
	},
	GetFullIFrame: function(){
		return "";
		//return ($.browser.msie?'<iframe width="100%" height="100%" style="z-index:-1;position:absolute;top:0;left:0;">':"");
	}
}

//窗体历史记录
Core.WinHistory = (function(){
	var _list = {};	//窗体库
	var _cache = {};	//缓存
	var _random = 0;	//游标
	var _zIndex = 99;
	var _old_active;
	var _bindState = false;
	
	//状态栏控制
	var status = (function(){
		var _stockTemp = '<li key="{key}"><b>{text}</b></li>';
		var _minTemp = '<li key="{key}"><b>{text}</b></li>';
		
		var getBox = function(statusType){
			return statusType == 0? $(Core.CONFIG.StockStatus):$(Core.CONFIG.MinStatus);
		}
		
		return {
			add: function(win){
				if(win.Setting.is_not_min_title){
					return;
				}
				var dom = $(String.formatmodel((win.StatusType == 0? _stockTemp:_minTemp),{key:win.Key,text:win.Setting.min_title}));
				dom.find("b").bind("click",function(e){
					if(!win.IsActive){
						win.Open();
					}
					else{
						win.Hide();
					}
					return false;
				});
				if($.browser.msie && $.browser.version == "6.0"){
					dom.find("b").hover(
					  function () {
						$(this).addClass("hover");
					  },
					  function () {
						$(this).removeClass("hover");
					  }
					);
				}
				getBox(win.StatusType).append(dom);
				
				return dom;
			},
			del: function(win){
				var box = getBox(win.StatusType);
				box.find("[key='"+win.Key+"']").empty().remove();
			},
			active: function(win){
				var box = getBox(win.StatusType);
				box.find("[key='"+win.Key+"'] b").removeClass("active").addClass("focus");
			},
			deactive: function(win){
				var box = getBox(win.StatusType);
				box.find("[key='"+win.Key+"'] b").removeClass("focus");
			},
			alarm: function(win){
				var box = getBox(win.StatusType);
				box.find("[key='"+win.Key+"'] b").addClass("active");
			}
		}
	})();
	
	var bindEvent = function(){
		if(!_bindState){
			$(window).bind("resize", function(){
				for(var k in _list){
					var win = _list[k];
					var h = win.Main.height();
					var w = win.Main.width();
					var wH = win.warp.height();
					var wW = win.warp.width();
					var wT = win.warp.offset().top;
					var wL = win.warp.offset().left;
					var mL = win.Main.offset().left;
					if(win.Setting.is_right){
						win.warp.height(h - wT - 5);
						win.warp.offset({left: mL + w-wW - Core.CONFIG.WinRightPX});
					}
					else{
						if((wL + wW) > w){
							var newL = w-wW - 5;
							if(newL < 0){
								wW = wW + newL;
								newL = 0;
							}
							if(!win.Setting.is_not_resize){
								if(wW < win.Setting.min_width){
									wW = win.Setting.min_width;
								}
								win.warp.width(wW);
							}
							win.warp.offset({left: newL});
						}
						if((wT + wH) > h){
							var newT = h-wH - 5;
							if(newT < 0){
								wH = wH + newT;
								newT = 0
							}
							if(!win.Setting.is_not_resize){
								if(wH < win.Setting.min_height){
									wH = win.Setting.min_height;
								}
								win.warp.height(wH);
							}
							win.warp.offset({top: newT});
						}
					}
				}
			})
			_bindState = true;
		}
	}
	
	return {
		//增加窗口历史记录
		Add: function(win){
			bindEvent();
			win.Key = win.Type + "_" + _random;
			_random++;
			_list[win.Key] = win;
			var dom = status.add(win);
			win.StatusDOM = dom;
		},
		//删除窗口历史记录
		Del: function(key){
			if(_list[key]){
				status.del(_list[key]);
				_list[key] = null
				delete _list[key];
			}
		},
		GetIndex: function(){
			return _zIndex++;
		},
		Active: function(win){
			if(_old_active && _old_active == win.Key){return;}
			_zIndex++;
			
			win.Active(_zIndex);
			win.IsActive = true;
			if(_old_active && _list[_old_active]){
				_list[_old_active].DeActive();
				_list[_old_active].IsActive = false;
				status.deactive(_list[_old_active]);
			}
			status.active(win);
			
			_old_active = win.Key;
		},
		Alarm: function(win){
			status.alarm(win);
		},
		DeOldActive: function(){
			if(_old_active && _list[_old_active]){
				_list[_old_active].DeActive();
				_list[_old_active].IsActive = false;
				status.deactive(_list[_old_active]);
				_old_active = false;
			}
		},
		DeActiveStatus: function(win){
			status.deactive(win);
			_old_active = false;
		}
	}
})();

//窗体头部
Core.WinTitle = (function(){
	var _temp = '<div class="title-bar" rel="base_title">{title}<div class="title-handle">{button}</div></div>';
	var _btns = [
		'<a href="javascript:;" class="ha-minimize" btn="hide">最小化</a>',
		'<a href="javascript:;" class="ha-maximize" btn="max">最大化</a><a href="javascript:;" class="ha-return" style="display:none" btn="revert">还原</a>',
		'<a href="javascript:;" class="ha-close" btn="close">关闭</a>'
	]
	
	var bindEvents = function(box, win){
		box.find("[btn]").mousedown(function(e){
			Core.Html.StopPropagation(e);
			Core.WinHistory.Active(win);
		}).click(function(e){
			win.SetButtonHandler($(this).attr("btn"));
			return false;
		})
	}
	
	return {
		Get: function(win){
			var html = _btns.join("");
			var box = $(String.formatmodel(_temp,{title:win.Setting.title,button:html}));
			bindEvents(box,win);
			return box;
		}
	}
})();

/*
	窗体基类
*/
Core.WindowBase = function(setting){
	var _temp = '<div class="window-container" style="display:none;" id="{key}_warp">' + Core.Html.GetShadow() + '<div id="{key}_inner" style="height:100%;"></div>' + Core.Html.GetFullIFrame() + '</div>';	//窗体模板

	var _resizeTemp = '<div resize="{resize_type}" style="position: absolute; overflow: hidden; background: url(static/js/transparent.gif) repeat scroll 0% 0% transparent; {css}"></div>'

	var _self = this;
	var _cache = { 
		resize:{ 
			"t": "left: 0; top: -3px; width: 100%; height: 5px; z-index: 1;",
			"r": "right: -3px; top: 0; width: 5px; height: 100%; z-index: 1;",
			"b": "left: 0; bottom: -3px; width: 100%; height: 5px; z-index: 1;",
			"l": "left: -3px; top: 0; width: 5px; height: 100%; z-index: 1;",
			"rt": "right: -3px; top: -3px; width: 10px; height: 10px; z-index: 2",
			"rb": "right: -3px; bottom: -3px; width: 10px; height: 10px; z-index: 2",
			"lt": "left: -3px; top: -3px; width: 10px; height: 10px; z-index: 2",
			"lb": "left: -3px; bottom: -3px; width: 10px; height: 10px; z-index: 2"
		}
	};
	
	//配置
	if(!setting){
		setting = {};
	}
	
	if(!setting.content){
		setting.content = "";
	}
	if(!setting.title){
		setting.title = "";
	}
	if(!setting.min_title){
		setting.min_title = "窗口";
	}
	
	this.warp;	//窗口DOM
	
	this.Type = "window";
	this.IsActive = false;
	
	this.StatusType = 0;	//状态栏类型	0,基本模式 1,小图标模式
	
	if(setting.Status != undefined){
		this.StatusType = setting.Status;
	}
	
	this.Setting = setting;
	this.Main;

	//绑字自定义拉伸
	var bindResize = function(resizeType,ele){
		var rt = "";
		switch(resizeType){
			case "t":
				rt = "n-resize";
				break;
			case "r":
				rt = "e-resize";
				break;
			case "b":
				rt = "s-resize";
				break;
			case "l":
				rt = "w-resize";
				break;
			case "rt":
				rt = "ne-resize";
				break;
			case "rb":
				rt = "se-resize"
				break;
			case "lb":
				rt = "sw-resize";
				break;
			 case "lt":
				rt = "nw-resize";
				break;
		}
		Util.Mouse.MoveLine(ele,rt,function(line){
			var xLess = line.eX - line.x;
			var yLess = line.eY - line.y;
			
			var w = _cache.resize_width;
			var h = _cache.resize_height;
			var t = _cache.resize_top;
			var l = _cache.resize_left;
			if(/l/.test(resizeType)){
				w = w - xLess;
				if(w < _cache.resize.min_width){
					l = _cache.resize_maxL;
				}
				else{
					l = l + xLess;
				}
			}
			if(/r/.test(resizeType)){
				w = w + xLess;
			}
			if(/b/.test(resizeType)){
				h = h + yLess;
			}
			if(/t/.test(resizeType)){
				h = h - yLess;
				if(h < _cache.resize.min_height){
					t = _cache.resize_maxT;
				}
				else{
					t = t + yLess;
				}
			}
			
			if(w < _cache.resize.min_width){
				w = _cache.resize.min_width;
			}

			if(h < _cache.resize.min_height){
				h = _cache.resize.min_height;
			}
			
			if(t < _cache.resize_mt){
				h = h - Math.abs(_cache.resize_mt - t);
				t = _cache.resize_mt;
			}
			
			if((t + h) > _cache.resize_mb){
				h =  _cache.resize_mb - t;
			}
			
			if(l < _cache.resize_ml){
				w = w - Math.abs(_cache.resize_ml - l);
				l = _cache.resize_ml;
				
			}
			
			if((l + w) > _cache.resize_mr){
				w = _cache.resize_mr + l;
			}
			
			_self.warp.css({width:w+"px",height:h + "px",top: t + "px",left:l+"px"});
			if(_self.Setting.is_right){
				_self.Setting.is_right = false;
			}
		},function(){
			var mainBox = _self.Main;
			_cache.resize_mt = mainBox.offset().top;
			_cache.resize_ml = mainBox.offset().left;
			_cache.resize_mr = _cache.resize_ml + mainBox.width();
			_cache.resize_mb = _cache.resize_mt + mainBox.height();
			_cache.resize_width = _self.warp.width();
			_cache.resize_height = _self.warp.height();
			_cache.resize_top = _self.warp.offset().top;
			_cache.resize_left = _self.warp.offset().left;
			_cache.resize_maxL = _cache.resize_left + _cache.resize_width - _cache.resize.min_width;
			_cache.resize_maxT = _cache.resize_top + _cache.resize_height - _cache.resize.min_height;
		});
	}
	
	//创建窗口
	var create = function(){
		if(!_cache.initState){
			_self.Main = Core.ACTIVE.GetMain();
			_cache.initState = true;
			Core.WinHistory.Add(_self);
			_cache.resize.min_width = _self.Setting.min_width = _self.Setting.min_width? _self.Setting.min_width: Core.CONFIG.WindowMinWidth;
			_cache.resize.min_height = _self.Setting.min_height = _self.Setting.min_height? _self.Setting.min_height: Core.CONFIG.WindowMinHeight;
			if(!_self.warp){
				_self.warp = $(String.formatmodel(_temp,{key:_self.Key}));
				var inner = _self.warp.find("#" + _self.Key + "_inner");
				if(!_self.Setting.is_not_resize){
					_cache.resize_list = [];
					for(var k in _cache.resize){
						var ele = $(String.formatmodel(_resizeTemp,{resize_type: k, css: _cache.resize[k]}));
						bindResize(k,ele);
						_self.warp.append(ele);
						_cache.resize_list.push(ele);
					}
				}
				if(!_self.Setting.is_not_title){	//判断是否需要头部
					_cache.title = Core.WinTitle.Get(_self);	//窗体头部
					inner.append(_cache.title);
				}
				
				inner.append(_self.Setting.content);
				
				if(_self.Setting.width != undefined){
					_self.warp.width(_self.Setting.width);
				}
				if(_self.Setting.height != undefined){
					_self.warp.height(_self.Setting.height);
				}
				
				var mainBox = _self.Main;
				
				//$(document.body).append(_self.warp);
				mainBox.append(_self.warp);
				
				if(_self.warp.height() > mainBox.height()){
					_self.warp.height(mainBox.height());
				}
			
				if(_self.Setting.position){
					_self.warp.css(_self.Setting.position);
				}
				else{
					Util.Layer.Center(_self.warp, {Main: mainBox});
				}
				
				Util.Mouse.MoveBox({
					ClickBox: _cache.title? _cache.title : _self.warp,
					Box: _self.warp,
					Outer: mainBox,
					Callback: function(){
						Core.WinHistory.Active(_self);
					},
					MoveCallback: function(){
						if(_self.Setting.is_right){
							_self.Setting.is_right = false;
						}
					}
				});
				if(!_self.Setting.is_not_resize){
					_cache.title.bind("dblclick", function(){
						if(!_self.MaxState){
							_self.Max();
						}
						else{
							_self.Revert();
						}
					});
				}
				else{
					_cache.title && _cache.title.find("[btn='max']").empty().remove();
					_cache.title && _cache.title.find("[btn='revert']").empty().remove();
				}
				
				if(_self.Setting.is_not_min_title){
					_cache.title && _cache.title.find(".win-minsize").empty().remove();
				}
				
				
				_self.warp.bind("mousedown",function(e){
					Core.WinHistory.Active(_self);
				})
				
				if(_self.Setting.is_max_window){
					_self.Max();
				}
			}
			if(_self.Initial){
				_self.Initial();
			}
		}
	}
	
	this.Max = function(){
		var mainBox = _self.Main;
		var w = mainBox.width(), h = mainBox.height();
		_self.MaxState = true;
		_cache.old_sq = {
			w: _self.warp.width(),
			h: _self.warp.height(),
			t: _self.warp.offset().top,
			l: _self.warp.offset().left
		}
		_self.warp.width(w).height(h).css({top: 0, left: 0});
		setTitleBtn();
		_self.Open();
	}

	this.Revert = function(){
		_self.MaxState = false;
		var w = _cache.resize.min_width, h = _cache.resize.min_height, t=0, l=0;
		if(_cache.old_sq){
			w = _cache.old_sq.w;
			h = _cache.old_sq.h;
			t = _cache.old_sq.t;
			l = _cache.old_sq.l;
		}
		_self.warp.width(w).height(h).css({top: t, left: l});
		setTitleBtn();
	}
	
	this.CreateDom = function(){
		create();
	}
	
	this.Hide = function(){
		_self.warp.hide();
		_self.DeActive();
		Core.WinHistory.DeActiveStatus(_self);
		_self.IsActive = false;
	}

	//打开
	this.Open = function(){
		create();	//新建窗体
		_self.warp.show();
		Core.WinHistory.Active(_self);
	}
	
	var setTitleBtn = function(){
		if(_self.MaxState){
			_cache.title.find("[btn='max']").hide();
			_cache.title.find("[btn='revert']").show();
			if(_cache.resize_list){
				for(var i = 0, len = _cache.resize_list.length; i < len; i++){
					_cache.resize_list[i].hide();
				}
			}
		}
		else{
			_cache.title.find("[btn='revert']").hide();
			_cache.title.find("[btn='max']").show();
			if(_cache.resize_list){
				for(var i = 0, len = _cache.resize_list.length; i < len; i++){
					_cache.resize_list[i].show();
				}
			}
		}
	}
	
	this.SetButtonHandler = function(type){
		switch(type){
			case "hide":
				_self.Hide();
				break;
			case "max":
				_self.Max();

				break;
			case "revert":
				_self.Revert();
				break;
			case "close":
				_self.Close();
				break;
		}
		
	}
	
	this.Close = function(){
		Core.WinHistory.Del(_self.Key);
		_cache.initState = false;
		_self.warp && _self.warp.hide();
		_self.MaxState = false;
	}
	
	//激活
	this.Active = function(zIndex){
		_self.warp.css({zIndex:zIndex}).addClass(Core.CONFIG.ActiveClass);
	}
	
	//取消激活
	this.DeActive = function(){
		_self.warp.removeClass(Core.CONFIG.ActiveClass);
	}
}

Core.WidgetBase = function(inter){
	var _temp = '<div class="user-info-plug" style="display:none;">' + Core.Html.GetShadow() + '<div rel="inner"></div><div class="widget-ctrl" style="display:none;" rel="base_side"><a href="javascript:;" class="close" btn="base_close">关闭</a><span class="drag"></span></div></div>';	//小插件模板
	var _self = this;
	
	this.Setting = {
		is_not_min_title: true
		
	}
	
	this.Main = Core.ACTIVE.GetMain();

	var _timer;
	var bindEvent = function(){
		if(inter.warp){
			
			inter.warp.find("[btn='base_close']").bind("mousedown", function(e){
				Core.Html.StopPropagation(e);
			}).bind("click", function(){
				_self.Close();
				return false;
			})
			
			inter.warp.mouseover(function(){
				if(_timer){
					window.clearTimeout(_timer);
				}
				$(this).find("[rel='base_side']").show();
			}).mouseout(function(){
				var ele = $(this);
				_timer = window.setTimeout(function(){
					ele.find("[rel='base_side']").hide();
				},50);
			})
			
			var mainBox = _self.Main;
			Util.Mouse.MoveBox({
				ClickBox: inter.warp,
				Box: inter.warp,
				Outer: mainBox,
				Callback: function(){
					Core.WinHistory.Active(_self);
				}
			});
		}
	}
	
	var initial = function(){
		if(!inter.warp){
			Core.WinHistory.Add(_self);
			inter.warp = $(_temp);
			inter.warp.append(inter.content);
			inter.warp.addClass(inter.className);

			//$(document.body).append(interface.warp);
			_self.Main.append(inter.warp);
			
			inter.position && inter.warp.css(inter.position);
			bindEvent();
			Core.WinHistory.Active(_self);
			_self.warp = inter.warp;
			
			
		}
		if(inter.Initial){
			inter.Initial();
		}
	}
	
	this.Hide = function(){
		if(inter.warp){
			inter.warp.hide();
		}
	}
	
	this.Close = function(){
		Core.WinHistory.Del(_self.Key);
		if(inter.warp){
			inter.warp.empty().remove();
			inter.warp = null;
			_self.warp = null;
		}
	}
	
	this.Open = function(){
		initial();
		if(inter.warp){
			inter.warp.show();
			Core.WinHistory.Active(_self);
		}
	}
	
	//激活
	this.Active = function(zIndex){
		inter.warp.css({zIndex:zIndex});
	}
	
	//取消激活
	this.DeActive = function(){
	}
}

Core.Extends = function(base, inter){
	base.call(this, inter);
}

Core.Dir = (function(){
    var _cache = {
        Handlers: []
    }
    
    return {
        Create: function(aid, cid){
            Core.Tree.CreateFolder(aid, cid, function(r){
                for(var i = 0, len = _cache.Handlers.length; i < len; i++){
                    var events = _cache.Handlers[i];
                    if(events.AddNode){
                        events.AddNode(r);
                    }
                }
            })
        },
        DoHandler: function(type, r){
            for(var i = 0, len = _cache.Handlers.length; i < len; i++){
                var events = _cache.Handlers[i];
                if(events[type]){
                    events[type](r);
                }
            }
        },
        Rename: function(aid, cid){
            var editCon = $('<div class="dialog-wrap popup-input">'+
                '<input type="text" rel="txt" class="text" />'+
                '</div>'+
                '<div class="dialog-bottom"><div class="fr">'+
                '<a href="javascript:;" class="button" btn="confirm"><span class="btn-con">确定</span></a>'+
                '<a href="javascript:;" class="button btn-gray" btn="cancel"><span class="btn-con">取消</span></a>'+
                '</div></div>');
            var editBox = new Core.DialogBase({
                title: '重命名文件夹',
                content: editCon
            });

            editBox.Open();
            Core.Tree.GetItem(cid,function(n){
                var node = n;
                editCon.find("[rel='txt']").val(node.name);

                var renameFolderFun = function(e){
                    var aid = e.data.aid;
                    var cid = e.data.cid;
                    Core.Tree.EditNode(aid, cid, editCon.find("[rel='txt']").val(), function(r){
                        if(r.state){
                            //改变数据列表数据
                            editBox.Close();
                            for(var i = 0, len = _cache.Handlers.length; i < len; i++){
                                var events = _cache.Handlers[i];
                                if(events.RenameNode){
                                    events.RenameNode(r);
                                }
                            }
                            Core.MinMessage.Show({
                                text: "成功重命名文件夹", 
                                type: "suc", 
                                timeout: Core.CONFIG.MsgTimeout
                            } );
                        }
                        else{
                            Core.MinMessage.Show({
                                text: r.message, 
                                type: "err", 
                                timeout: Core.CONFIG.MsgTimeout, 
                                window: editBox
                            } );
                            editCon.find("[rel='txt']")[0].focus();
                        }
                    })
                }

                editCon.find("[rel='txt']").bind("keydown", {
                    aid: aid, 
                    cid: cid
                }, function(e){
                    if(e.keyCode == 13){
                        renameFolderFun(e);
                    }
                    else if(e.keyCode == 27){
                        editBox.Close();
                    }
                })

                editCon.find("[btn]").bind("click", {
                    aid: aid, 
                    cid: cid
                },function(e){
                    switch($(this).attr("btn")){
                        case "confirm":
                            renameFolderFun(e);
                            break;
                        case "cancel":
                            editBox.Close();
                            break;
                    }
                    return false;
                })

                editCon.find("[rel='txt']")[0].focus();
                window.setTimeout(function(){
                    editCon.find("[rel='txt']")[0].select();
                },20);
            });
        },
        AddDoHandler: function(listen){
            _cache.Handlers.push(listen);
        },
        Delete: function(aid, cid){
            var item = Core.Tree.GetItem(cid);
            var pid = item.pid;
            if(pid.toString().indexOf("_0") != -1){
                pid = 0;
            }
            Core.Message.Confirm({
                type: "war", 
                text: "确认要删除此文件夹吗？",
                content:"删除到回收站的文件夹暂时不会被永久删除，您可以到回收站来永久删除或还原这个文件夹。", 
                win:_cache.win, 
                callback: function(r){
                    if(r){
                        var url = PAGE_PATHS["MY"]+"/index.php?r=operate/index&ct=file&ac=delete";
                        var data = {
                            aid: aid,
                            pid: pid,
                            cid: cid
                        };
                        $.ajax({
                            url: url,
                            type: "POST",
                            data: data,
                            dataType: "json",
                            success: function(r){
                                //删除目录树DOM
                                if(r.state){
                                    Core.MinMessage.Show({
                                        text: "删除成功", 
                                        timeout: Core.CONFIG.MsgTimeout,
                                        type:"suc"
                                    });
                                    Core.Tree.DeleteNode(cid);
                                    if(Core.FileConfig.DataAPI) Core.FileConfig.DataAPI.DelOne(aid, pid, cid, 0); 
                                }
                                else{
                                    Core.MinMessage.Show({
                                        text: "删除失败", 
                                        timeout: Core.CONFIG.MsgTimeout,
                                        type:"err"
                                    });
                                }
                            }
                        });
                    }

                }
            });
        },
        Shared: function(aid, cid, is_share){
            var item = Core.Tree.GetItem(cid);
            var pid = item.pid;
            if(pid.toString().indexOf("_0") != -1){
                pid = 0;
            }
            var url = "?ct=file&ac=share";
            var data = {
                aid: aid,
                pid: pid,
                cid: cid,
                is_share: is_share
            };
            $.ajax({
                url: url,
                type: "POST",
                data: data,
                dataType: "json",
                success: function(r){
                    var msg = is_share? "分享": "取消分享";
                    if(r.state){
                        Core.Tree.SharedNode(cid, is_share);
                        if(Core.FileConfig.DataAPI) Core.FileConfig.DataAPI.ShareOne(aid, pid, data.is_share, cid, 0);
                        Core.MinMessage.Show({
                            text: msg + "成功", 
                            timeout: Core.CONFIG.MsgTimeout,
                            type:"suc"
                        });
                    }
                    else{
                        Core.MinMessage.Show({
                            text: msg + "失败", 
                            timeout: Core.CONFIG.MsgTimeout,
                            type:"err"
                        });
                    }
                }
            });
        }
    }
})();

/*
	目录树
*/
Core.Tree = (function(){
	var _fileICO = Core.CONFIG.ICOType;	//文件夹图标
	var tree_dom;	//目录树DOM缓存
	var item_temp = '<li title="%2"><a href="javascript:;" cid="%1" aid="%4" pid="%5"><i class="imenu %3"></i><em rel="text">%2</em></a></li>';
    var first_temp = '<dt title="%2"><a href="javascript:;" cid="%1" aid="%4" pid="%5"><i class="imenu %3"></i><em rel="text">%2</em></a></dt><dd style="display:none;"></dd>';
    var open_temp = '<i class="ind" rel="open"></i>';
    var _paddingLen = 15;	//padding-left 长度
	var _defaultLen = 20;
    var Return = {},_cache = {FirestNodes:[]};

    var ajaxLoadDir = function(callback){
        if(!_cache.is_loading_tree){
            _cache.is_loading_tree = true;
            Core.MinMessage.Show({text: "正在加载目录，请稍候...", type: "load", timeout:10000});
            $.ajax({
                url: PAGE_PATHS["MY"]+"/index.php?r=operate/index&ct=dir&ac=get",
                dataType: "json",
                cache:false,
                type: "GET",
                success: function(r){
                    Core.MinMessage.Hide();
                    if(r.state){
                        _cache.is_loading_tree = true;
                        Core.Tree.SetData(r.data);
                        if(callback) callback();
                    }
                }
            })
        }
    }
    
    Return.CheckIsLoad = function(callback){
        if(_cache.Data){
            callback && callback();
        }
        else{
            ajaxLoadDir(callback);
        }
    }

    var exportData = function(){
		for(var k in _cache.Data){
			if(Number(_cache.Data[k].aid) == 7){
				_cache.Data[k] = null;
				delete _cache.Data[k];
				continue;
			}
            var pid = _cache.Data[k].pid.toString();
            if(pid && _cache.Data[pid]){
                if(!_cache.Data[pid].childs){
                    _cache.Data[pid].childs = [];
                }
                _cache.Data[pid].childs.push(k);
            }
            if(pid == "0"){
                _cache.FirestNodes.push(k);
            }
        }
    }
    
	var bindEvents = function(dom){
        dom.find("i[rel='open']").bind("click",function(e){
            Core.Html.StopPropagation(e);
            var ele = $(this);
            var li = ele.parent().parent();
            var ul;
            var isfirst = false;
            if(ele.parent().attr("pid") == 0){
                ul = li.next();
                isfirst = true;
            }
            else{
                ul = li.find("ul:first");
            }
            if(ele.hasClass("ino")){
                ele.removeClass("ino");
                ul.hide();
                if(isfirst){
                    ul.find("ul:first").hide();
                }
            }
            else{
                ele.addClass("ino");

                ul.show();
                if(isfirst){
                    ul.find("ul:first").show();
                }
            }
            if(ele.parent()[0]){
                ele.parent()[0].blur();
            }
            return false;
        });
    }
    
    var openParents = function(cid, pdom){
        var arr = Return.GetParents(cid);
        for(var i = 0, len = arr.length; i < len; i++){
            var itemCid = arr[i];
            openNode(itemCid,pdom);
        }
    }
    
    var openNode = function(cid, pdom){
        for(var i = 0,len = pdom.length; i < len; i++){
            var dom = pdom[i];
            var a = dom.find("[cid='"+cid+"']");

            if(a.length){
                var ele = a.find("i[rel='open']");
                if(ele.length){
                    ele.addClass("ino");
                    if(a.attr("pid") == "0"){
                        var next = a.parent().next();
                        next.show();
                        next.find("ul:first").show();
                    }
                    else{
                        a.parent().find("ul:first").show();
                    }
                }
            }
        }
    }
    
    //打开节点
	Return.OpenChild = function(cid,pdom){
		if(pdom){
            openParents(cid, pdom);
			openNode(cid, pdom);
		}
	}
    
    //隐藏节点
    Return.HideChild = function(cid, pdom){
        if(pdom){
			for(var i = 0,len = pdom.length; i < len; i++){
				var dom = pdom[i];
				var a = dom.find("[cid='"+cid+"']");
                
				if(a.length){
					var ele = a.find("i[rel='open']");
					if(ele.length){
						ele.removeClass("ino");
                        if(a.attr("pid") == "0"){
                            var next = a.parent().next();
                            next.hide();
                            next.find("ul:first").hide();
                        }
                        else{
                            a.parent().find("ul:first").hide();
                        }
					}
				}
			}
		}
    }
	
	var getChilds = function(obj,dom,index,padlen){
        index++;
        
        var a = dom.find("a:first");
        
        if(padlen == undefined){
			padlen = _defaultLen;
		} 
        a.css({paddingLeft: padlen + index*_paddingLen + "px"});
        
        if(obj.childs && obj.childs.length){
            if(index != 0){
                a.prepend(open_temp);
            }
            else{
                dom.prev().find("a").prepend(open_temp);
            }

            var ul = $('<ul pid="'+obj.cid+'"></ul>');
            ul.hide();

            dom.append(ul);
            for(var i = 0, len = obj.childs.length; i < len; i++){
                var item = _cache.Data[obj.childs[i]];
                var ico = _fileICO.Default;
                if(item.is_share == 1){
                    ico = _fileICO.share;
                }
                
                var li = $(String.format(item_temp,item.cid,item.name,ico,item.aid, item.pid));
                li.find("a").attr("title",item.name);
                
                var childLis = ul.children();
                if(childLis.length){
                    var nextLi = false;
                    for(var j = 0, jl = childLis.length; j < jl; j++){
                        var n = _cache.Data[$(childLis[j]).find("a").attr("cid")];
                        if(!nextLi && n["s"] < item["s"]){
                            nextLi = $(childLis[j]);
                        }
                    }
                    if(nextLi){
                       li.insertBefore(nextLi); 
                    }
                    else{
                       ul.append(li); 
                    }
                }
                else{
                    ul.append(li);
                }
                
                getChilds(item,li,index);
            }
        }
    }
	
	//获取树DOM
	var getTreeDom = function(padlen){
        if(_cache.Data){
            if(_cache.FirestNodes.length){
                var result = [];
                for(var i = 0,len = _cache.FirestNodes.length; i < len; i++){
                    var item = _cache.Data[_cache.FirestNodes[i]];
                    var ico = _fileICO.Default;
                    if(_fileICO[item.cid]){
                        ico = _fileICO[item.cid];
                    }
                    var dom = $(String.format(first_temp,item.cid,item.name,ico,item.aid, item.pid));
                    getChilds(item, $(dom[1]), -1, padlen);
                    bindEvents(dom);
                    result.push(dom);
                }

                return result;
            }
        }
        return null;
    }
    
    Return.GetItem = function(cid, callback){
        if(callback){
            Return.CheckIsLoad(function(){
                var d = _cache.Data;
                
                callback && callback(_cache.Data[cid]);
            })
        }
        else{
            return _cache.Data[cid];
        }
    }
    
    Return.GetTreeHtml = function(padlen){
        var lis = getTreeDom(padlen);
        var result = [];
        for(var k in lis){
            var li = lis[k];
            var html = [];
            li.each(function(){
                var ele = $(this);
                var tagName = ele[0].tagName;
                if(tagName == "DD"){
                    html.push('<' + tagName + ' style="display:none;">' + ele.html() + '</'+tagName+'>');
                }
                else{
                    html.push('<' + tagName + ' title="'+ele.attr("title")+'">' + ele.html() + '</'+tagName+'>');
                }
            })
            result.push(html.join(""));
        }
        return result;
    }
	
	//设置目录树数并重新解析数据
	Return.SetData = function(treeData){
		_cache.Data = treeData;
		exportData();
	}
    
	//获取目录树DOM
	Return.GetTree = function(padlen){
		if(padlen != undefined){
			return getTreeDom(padlen);
		}
		if(!tree_dom){
			tree_dom = getTreeDom();
		}
		return tree_dom;
	}

	var updateTreeCache = function(){
		tree_dom = getTreeDom();
	}

	var getParents = function(res,cid,isobj){
		if(cid){
            var obj = _cache.Data[cid.toString()];
            
            if(obj && obj.pid){
                if(isobj){
                    res.arr.push(_cache.Data[obj.pid]);
                }
                else{
                    res.arr.push(obj.pid);
                }
                getParents(res,obj.pid,isobj);
            }
		}
    }

	//获取父节点列表
    Return.GetParents = function(cid,isobj){
        var res = {};
        res.arr = [];
        getParents(res,cid,isobj);
        var arr = res.arr;
        return arr;
    }
	
	Return.GetNode = function(cid){
		return _cache.Data[cid];
	}
	
	Return.BindDoms = function(){
		var arr = arguments;
		for(var i = 0,len = arr.length; i < len; i++){
			if(!_cache.BindDoms){
				_cache.BindDoms = []
			}
			_cache.BindDoms.push(arr[i]);
		}
	}
	
	//重命名文件夹
	Return.EditNode = function(aid, cid, floderName, callback){
		var data = {
			aid: aid,
			cid: cid,
			cname: floderName
		}
		$.ajax({
			url: PAGE_PATHS["MY"]+"/index.php?r=operate/index&ct=dir&ac=edit",
			type: "POST",
			dataType: "json",
			data: data,
			success: function(result){
				if(result.state){
                    if(_cache.Data){
                        _cache.Data[cid].name = floderName;
                    }
					updateTreeCache();
					if(_cache.BindDoms){
						for(var i = 0,len = _cache.BindDoms.length; i < len; i++){
							var dom = _cache.BindDoms[i];
							dom.find("a[cid='"+cid+"'] [rel='text']").html(result.cname);
						}
					}
				}
				if(callback){
					callback(result);
				}
			}
		});
	}
	
	var addNodeToDom = function(dom, newcid, aid, cid, longIndex, result){
		var nodes = dom.find("li a");
		if(nodes.length){
			var a = $(nodes[0]).clone(true);

			a.attr("cid",newcid).attr("aid",aid).attr("pid", cid).html('<i class="imenu ico-folder"></i><em rel="text">' + result.cname + '</em>');
			a.css({paddingLeft: _defaultLen + longIndex*_paddingLen + "px"}).attr("class","");
			var addNode = $("<li></li>");
			addNode.append(a);
			if(cid){
				var ul = dom.find("ul[pid='"+cid+"']");
				if(!ul.length){
					ul = $(String.format('<ul pid="'+cid+'"></ul>'));
					var pLi = dom.find("a[cid='"+cid+"']").parent();
					var icon = _fileICO[cid]? _fileICO[cid] : _fileICO.Default;
					if(_cache.Data[cid.toString()].is_share != undefined && _cache.Data[cid.toString()].is_share.toString() == "1"){
						icon = _fileICO.share;
					}
					dom.find("a[cid='" + cid + "'] i."+icon).before('<i class="ind ino" rel="open"></i>');
					bindEvents(pLi);
					ul.append(addNode);
                    if(_cache.Data[cid.toString()].pid == 0){
                        pLi.next().show().append(ul);
                    }
                    else{
                        pLi.append(ul);
                    }
				}
				else{
					var lis = ul.find("li");
					/*if(lis.length){
						$(lis[0]).before(addNode);
					}
					else{
						ul.append(addNode);
					}*/
                    ul.append(addNode);
				}
			}
			else{
				dom.append(addNode);
			}
		}
	}
	
    Return.APICreateNodeDom = function(aid, pid, result, notfresh){
        if(result.state){
            var newcid = result.cid.toString();
            
            var longIndex = 0;
            /**改变数据模型**/
            var cid = pid;
            if(Number(pid) == 0){
                cid = aid + "_0";
            }
            if(!_cache.Data){return;}
            _cache.Data[newcid] = {aid: aid, pid:cid, cid:newcid, name:result.cname};
            if(!_cache.Data[cid.toString()].childs){
                _cache.Data[cid.toString()].childs = [];
            }
            _cache.Data[cid.toString()].childs.push(newcid);
            updateTreeCache();
            longIndex = Core.Tree.GetParents(newcid).length;

            if(_cache.BindDoms){
                for(var i = 0,len = _cache.BindDoms.length; i < len; i++){
                    var dom = _cache.BindDoms[i];
                    addNodeToDom(dom,newcid,aid,cid,longIndex,result);
                    dom.find("a[cid='"+newcid+"']").click();
                }
            }

            result["not_refresh"] = notfresh;

            Core.Dir.DoHandler("AddNode", result);
        }
    }
    
	//新建文件夹
	Return.CreateNode = function(aid, pid, floderName, callback, notfresh){
		var r = Util.Validate.CategoryName($.trim(floderName));
		if(r !== true){
			if(callback){
				callback({state: false, message: r});
			}
			return;
		}
		var data = {
			aid: aid,
			pid: pid,
			cname: floderName
		}
		$.ajax({
			url: PAGE_PATHS["MY"]+"/index.php?r=operate/index&ct=dir&ac=add",
			type: "POST",
			dataType: "json",
			data: data,
			success: function(result){
				if(result.state){
					var newcid = result.cid.toString();
					
					var longIndex = 0;
					/**改变数据模型**/
					var cid = pid;
					if(Number(pid) == 0){
						cid = aid + "_0";
					}
                    if(_cache.Data){
                        _cache.Data[newcid] = {aid: aid, pid:cid, cid:newcid, name:result.cname};
                        if(!_cache.Data[cid.toString()].childs){
                            _cache.Data[cid.toString()].childs = [];
                        }
                        _cache.Data[cid.toString()].childs.push(newcid);
                        updateTreeCache();
                        longIndex = Core.Tree.GetParents(newcid).length;

                        if(_cache.BindDoms){
                            for(var i = 0,len = _cache.BindDoms.length; i < len; i++){
                                var dom = _cache.BindDoms[i];
                                addNodeToDom(dom,newcid,aid,cid,longIndex,result);
                                dom.find("a[cid='"+newcid+"']").click();
                            }
                        }
                    }
                    
                    result["not_refresh"] = notfresh;
                    
                    Core.Dir.DoHandler("AddNode", result);
				}
				if(callback){
					callback(result);
				}
			}
		})
	}
	
	//递归删除子目录
	var deleteChilds = function(cid){
		if(_cache.Data[cid.toString()]){
			var childs = _cache.Data[cid.toString()].childs;
			if(childs && childs.length){
				for(var i = 0, len = childs.length; i < len; i++){
					var obj = _cache.Data[childs[i]];
					if(obj){
						deleteChilds(obj.cid);
					}
				}
			}
			_cache.Data[cid.toString()] = null;
			delete _cache.Data[cid.toString()];
		}
	}
	
	//删除目录
	Return.DeleteNode = function(cid){
        if(!_cache.Data) return;
        
		var obj = _cache.Data[cid.toString()];
		pid = obj.pid;
		
		if(obj){
			var pobj = _cache.Data[pid.toString()];
			//删除父级目录的标记
			if(pobj && pobj.childs){
				var delIndex;
				for(var i = 0,len = pobj.childs.length; i < len; i++){
					var item = pobj.childs[i];
					if(Number(cid) == Number(item)){
						delIndex = i;
						break;
					}
				}
				if(delIndex != undefined){
					_cache.Data[pid.toString()].childs.splice(delIndex,1);
				}
			}
			deleteChilds(cid);	//递归删除子目录
			_cache.Data[cid.toString()] = null;
			delete _cache.Data[cid.toString()];	//清除本身
			updateTreeCache();
		}
		
		//删除DOM
		if(_cache.BindDoms){
			for(var i = 0,len = _cache.BindDoms.length; i < len; i++){
				var dom = _cache.BindDoms[i];
                var a = dom.find("a[cid='"+cid+"']");
                if(a.hasClass("focus")){
                    dom.find("a[cid='"+a.attr("pid")+"']").click();
                }
				var li =  a.parent();
				var ul = li.parent();

				li.empty().remove();
				if(!ul.find("li").length){
					var pid = ul.attr("pid");
                    var dd = ul.parent();
					ul.empty().remove();
					_cache.BindDoms[i].find("[cid='"+pid+"'] i[rel='open']").empty().remove();
                    if(pid.toString().indexOf("_0") != -1){
                        dd.hide();
                    }
				}
			}
		}
        Core.Dir.DoHandler("DeleteNode", {cid: cid, pid: pid});
	}
	
	//分享目录
	Return.SharedNode = function(cid, share){
        if(!_cache.Data) return;
        var obj = _cache.Data[cid.toString()];
        if(obj){
            obj.is_share = Number(share);
        }
		if(_cache.BindDoms){
			
			updateTreeCache();
			for(var i = 0,len = _cache.BindDoms.length; i < len; i++){
				var dom = _cache.BindDoms[i];
				var ele = dom.find("a[cid='"+cid+"'] i").not("[rel]");
				var ico;
				if(share){
					ico = _fileICO.share;
				}
				else{
					ico = _fileICO.Default;
				}
				if(ico){
					ele.removeClass().addClass("imenu").addClass(ico);
				}
			}
		}
        
        Core.Dir.DoHandler("ShareNode", {cid:cid, share:share});
	}
	
	var addNodeHide = function(dom){
		if(_cache.createCacheDom && _cache.createDom){
			_cache.createCacheDom.append(_cache.createDom);
		}
		if(dom){
            
			if(dom.attr("cache") == "1"){
                var par = dom.parent();
				dom.empty().remove();
                if(par.attr("aid")){
                    par.hide();
                }
			}
		}
	}

	Return.AddNode = function(dom, treeBox, callback, notfresh){
		var ele = dom.find("a.focus");
		var aid = ele.attr("aid");
		var cid = ele.attr("cid");
		if(!_cache.createDom){
			//创建缓存DOM
			_cache.createDom = $('<li><span rel="padding"><i class="imenu ico-folder"></i><input type="text" rel="name" maxlength="20" style="width:100px;" /><input type="hidden" rel="aid"/><input type="hidden" rel="pid"/><button type="button" class="confirm" rel="min_confirm"><i>确定</i></button><button type="button btn-gray" class="cancel" rel="min_cancel"><i>取消</i></button> </span></li>');
			_cache.createCacheDom = $('<ul style="display:none"></ul>');
			_cache.createCacheDom.append(_cache.createDom);
			$(document.body).append(_cache.createCacheDom);
		}
		
		var createNodeFun = function(){
			var name = $.trim(_cache.createDom.find("[rel='name']").val());
			var pid = _cache.createDom.find("[rel='pid']").val();
			var aid = _cache.createDom.find("[rel='aid']").val();
			
			Return.CreateNode(aid,pid,name,function(result){
				if(result.state){
					addNodeHide(_cache.createDom.parent());
					var newcid = result.cid.toString();
					var longIndex = Core.Tree.GetParents(newcid).length;
                    addNodeToDom(treeBox,newcid,aid,pid,longIndex, result);
					
					if(callback){
						callback(newcid);
					}
				}
				else{
					Core.MinMessage.Show({text: result.message, type: "err", timeout: Core.CONFIG.MsgTimeout} );
					_cache.createDom.find("[rel='name']").focus();
				}
			},notfresh);
		}
		
		//绑定事件
		_cache.createDom.find("[rel='min_confirm']").unbind("click").bind("click",function(e){
			createNodeFun();
		})
		_cache.createDom.find("[rel='min_cancel']").unbind("click").bind("click",function(e){
			addNodeHide(_cache.createDom.parent());
		})
		_cache.createDom.find("[rel='name']").unbind("keydown").bind("keydown",function(e){
			if(e.keyCode == 13){
				createNodeFun();
			}
			else if(e.keyCode == 27){
				addNodeHide(_cache.createDom.parent());
			}
		})
		
		//移动缓存DOM
        var ul;
		if(cid.indexOf("_0") != -1){
            ul = ele.parent().next().find("ul[pid='"+cid+"']");
            if(!ul.length){
                ul = $('<ul cache="1"></ul>');
                ele.parent().next().show().append(ul);
            }
        }
        else{
            ul = ele.parent().find("ul[pid='"+cid+"']");
            if(!ul.length){
                ul = $('<ul cache="1"></ul>');
                ele.parent().append(ul);
            }
        }
        var addlen = 0;
        if(ele.attr("cid").indexOf("_0") == -1){
            addlen = _paddingLen;
        }
        else{
            addlen = -_paddingLen;
        }
		var paddingLeft = Number(ele.css("padding-left").replace("px","")) + addlen;
        
		_cache.createDom.find('[rel="padding"]').css({paddingLeft:paddingLeft + "px"});
		//var childList = ul.children();
        ul.append(_cache.createDom);
        /*if(childList.length){
            var fNode = $(childList[0]);
            _cache.createDom.insertBefore(fNode);
        }
        else{
            ul.append(_cache.createDom);
        }*/
		//塞值
		_cache.createDom.find("[rel='pid']").val(cid);
		_cache.createDom.find("[rel='aid']").val(aid);
		
		Core.Tree.OpenChild(cid,[dom]);
		_cache.createDom.find("[rel='name']").val("").focus();
	}
    
    Return.CreateFolder = function(aid, cid, fun, win){
        var addCon = $('<div class="dialog-wrap popup-input">'+
                            '<input type="text" class="text" rel="txt" />'+
                        '</div>'+
                        '<div class="dialog-bottom">'+
                            '<div class="fr">'+
                                '<a href="javascript:;" class="button" btn="confirm"><span class="btn-con">确定</span></a>'+
                                '<a href="javascript:;" class="button btn-gray" btn="cancel"><span class="btn-con">取消</span></a>'+
                            '</div>'+
                        '</div>');
        var createBox = new Core.DialogBase({
            title: '新建文件夹',
            content: addCon
        });
        createBox.Open(null, win);
        var addFolderFun = function(e){
            var aid = e.data.aid;
            var cid = e.data.cid;
            Core.Tree.CreateNode(aid, cid, addCon.find("[rel='txt']").val(), function(r){
                if(r.state){
                    var newcid = r.cid;
                    
                    Core.MinMessage.Show({
                        text: "新建成功", 
                        type: "suc", 
                        timeout: Core.CONFIG.MsgTimeout, 
                        window: createBox
                    } );
                    createBox.Close();
                }
                else{
                    Core.MinMessage.Show({
                        text: r.message, 
                        type: "err", 
                        timeout: Core.CONFIG.MsgTimeout, 
                        window: createBox
                    } );
                    addCon.find("[rel='txt']")[0].focus();
                }
            })
        }

        addCon.find("[rel='txt']").bind("keydown", {
            aid: aid, 
            cid: cid
        }, function(e){
            if(e.keyCode == 13){
                addFolderFun(e);
            }
            else if(e.keyCode == 27){
                createBox.Close();
            }
        })
		
        addCon.find("[btn]").bind("click", {
            aid: aid, 
            cid: cid
        },function(e){
            switch($(this).attr("btn")){
                case "confirm":
                    //新建文件夹
                    addFolderFun(e);
                    break;
                case "cancel":
                    createBox.Close();
                    break;
            }
            return false;
        })
        addCon.find("[rel='txt']")[0].focus();
    }
	
	//还原一批目录
	var restoreDir = function(data){
		var co = 0;
		for(var k in data){
			var item = data[k];
			if(_cache.Data[item.pid]){
				_cache.Data[k] = item;
				if(!_cache.Data[item.pid].childs){
					_cache.Data[item.pid].childs = [];
				}
				_cache.Data[item.pid].childs.push(k);
				//更新UI
				if(_cache.BindDoms){
					for(var i = 0,len = _cache.BindDoms.length; i < len; i++){
						var dom = _cache.BindDoms[i];
						var nodes = dom.find("li a");
						if(nodes.length){
							var longIndex = Core.Tree.GetParents(item.cid).length;
							var a = $(nodes[0]).clone(true);
							var icon = _fileICO.Default;
							if(item.is_share != undefined && item.is_share.toString() == "1"){
								icon = _fileICO.share;
							}
							a.attr("cid",item.cid).attr("aid",item.aid).html('<i class="imenu '+icon+'"></i><em rel="text">' + item.name + "</em>");
							a.css({paddingLeft: _defaultLen + longIndex*_paddingLen + "px"}).attr("class","");
							var addNode = $("<li></li>");
							addNode.append(a);
							if(item.pid){
								var ul = dom.find("ul[pid='"+item.pid+"']");
								if(!ul.length){
									ul = $(String.format('<ul pid="'+item.pid+'"></ul>'));
									var pLi = dom.find("a[cid='"+item.pid+"']").parent();
									var icon = _fileICO[item.pid]? _fileICO[item.pid] : _fileICO.Default;
									if(_cache.Data[item.pid.toString()].is_share != undefined && _cache.Data[item.pid.toString()].is_share.toString() == "1"){
										icon = _fileICO.share;
									}
									dom.find("a[cid='"+item.pid+"'] i."+icon).before('<i rel="open" class="ind ino"></i>');
									bindEvents(pLi);
									ul.append(addNode);
                                    if(item.pid.toString().indexOf("_0") != -1){
                                        pLi.next().show().append(ul);
                                    }
                                    else{
                                        pLi.show().append(ul);
                                    }
								}
								else{
                                    ul.append(addNode);
									/*var lis = ul.find("li");
									if(lis.length){
										$(lis[0]).before(addNode);
									}
									else{
										ul.append(addNode);
									}*/
								}
							}
							else{
								dom.append(addNode);
							}
						}
					}
				}

				delete data[k];
			}
			else{
				co++;
			}
		}
		if(co){
			restoreDir(data);
		}
		else{
			return;
		}
	}

	//数据沙箱转换
	Return.Sandbox = function(data){
        if(!_cache.Data) return;
		var markList = {};
        var oldList = {};
		for(var k in data){
			if(!_cache.Data[k] && data[k].aid != 7){
				markList[k] = data[k];
                oldList[k] = data[k];
			}
		}
		restoreDir(markList);
        
        Core.Dir.DoHandler("RestoreNode", oldList);
	}
	
	return Return;
})()

/*空间大小管理器*/
Core.SpaceData = (function(){
	var _data;

	var _OberverData = [];	//空间大小改变后观察对象
	//改变空间数据
	var changeData = function(changeType,aid,iByte,isdel){
		var result = true;
		var key = -1;
		switch(Number(aid)){
			case 0:
				key = 0;
				break;
			default:
				key = 1;
				break;
		}
		if(!_data[key.toString()]){
			_data[key.toString()] = {};
		}
		var obj = _data[key.toString()];
		if(obj){
			switch(isdel){
				case 0:
				obj[changeType] = Number(obj[changeType]) - Number(iByte);
				break;
				case 1:
				if(changeType == "used"){
					var use = Number(obj[changeType]) + Number(iByte);
					if(use > obj["total"]){
						result = false;
					}
					else{
						obj[changeType] = use;
					}
				}
				else{
					obj[changeType] = Number(obj[changeType]) + Number(iByte);
				}
				break;
				case 2:
				obj[changeType] = Number(iByte);
				break;
			}

			doClient();
		}
		else{
			result = false;
		}
		return result;
	}
    
    var translation = function(d){
        //{"1":{"upload_size_limit":"0","upload_validity":"0","size_used":7580642419,"size_total":68957503488,"size_remain":61376861069,"size_used_percent":10.993208912093}}
        
        //{"1":{"total":68957503488,"used":7580642419}}
        for(var k in d){
            var item = d[k];
            d[k]["total"] = item["total"]? item["total"]: item["size_total"];
            d[k]["used"] = item["used"] !=undefined? item["used"] : item["size_used"];
            d[k]["size_remain"] = Number(item["size_remain"]);
        }
    }
    
    var doClient = function(){
        if(_OberverData.length){
            var delKeys = [];
            var newList = [];
            for(var i = 0,len = _OberverData.length; i < len; i++){
                try{
                    if(_OberverData[i]){
                        _OberverData[i].Do(_data);
                        newList.push(_OberverData[i]);
                    }
                    else{
                        delKeys.push(i);
                    }
                }catch(e){
                    delKeys.push(i);
                }
            }

            if(delKeys.length){
                //过滤已丢失被观察者
                _OberverData = newList;
            }
        }
    }
    
	//同步空间占用数据
	var syncMethod = function(callback){
		var url = PAGE_PATHS["MY"]+"/index.php?r=operate/index&ct=ajax_user&ac=get_space_info";	//修改AJAX接口
		$.ajax({
			url:url,
			method:"GET",
			dataType:"json",
			cache:false,
			success:function(result){
                translation(result);
				for(var key in result){
					_data[key] = result[key];
				}
				doClient();
				if(callback){
					callback();
				}
			}
		});
	}
	
	return {
		AddClient: function(key,fun){
			//增加观察对象
			if(fun){
                var addRes = true;
                for(var i = 0, len = _OberverData.length; i < len; i++){
                    var obj = _OberverData[i];
                    if(obj.Key == key){
                        obj.Do = fun;
                        addRes = false;
                    }
                }
                if(addRes){
                    _OberverData.push({Key:key, Do:fun});
                }
                doClient();
			}
		},
		ChangeUse: function(aid,iByte,isdel){
			//改变已使用空间大小
			if(iByte == ""){iByte = 0;}
			return changeData("used",aid,iByte,isdel);
		},
		ChangeTotal: function(aid,iByte,isdel){
			//改变总空间大小
			if(iByte == ""){iByte = 0;}
			return changeData("total",aid,iByte,isdel);
		},
		GetData: function(){
			return _data;
		},
		SetData: function(data){
            translation(data);
			_data = data;
		},
        IsNoSpace: function(type){
            if(type == undefined){
                type = "1";
            }
            if(_data[type]){
                return (_data[type]["size_remain"] < 0);
            }
            return false;
        },
		Sync: function(callback){
			syncMethod(callback);
		}
	};
})();

/*
	迷你信息提示
*/
Core.MinMessage = (function(){
	var _temp = '<div class="popup-hint" style="z-index:9999999999;"><div class="popup-content"><i class="i-hint" rel="type"></i><span class="popup-hint-text" rel="con"></span><b class="popup-bg"></b><b class="cor-s sl"><i></i></b><b class="cor-s sr"><i></i></b></div></div>';
	var _cache = {
		Type:{
			"suc": "ico-suc",
			"war": "ico-war",
			"err": "ico-err",
			"load": "ico-load"
		}
	}, _dom, _timer;
	
	//创建消息DOM
    var create = function(text,type){
        if(!_dom){
            _dom = $(String.format(_temp,text));
            $(document.body).append(_dom);
        }
        _dom.find("[rel='con']").html(text);
        var icon = _dom.find("[rel='type']");
		for(var k in _cache.Type){
            icon.removeClass(_cache.Type[k]);
        }
        icon.addClass(_cache.Type[type]);
    }
	
	//隐藏
    var hide = function(){
        if(_timer){
            window.clearTimeout(_timer);
        }
        if(_dom){
            _dom.hide();
        }
    }

    return {
        Show: function(obj){
            if(!obj.type){
                obj.type = "war";
            }
            create(obj.text,obj.type);
			Util.Layer.Center(_dom,{Main:obj.window?obj.window.warp:false});
            _dom.show();
            if(_timer){
                window.clearTimeout(_timer);
            }
            if(obj.timeout){
                _timer = window.setTimeout(hide,obj.timeout);
            }
        },
        Hide: function(){
            hide();
        }
    }
})();

/*
	对话框
*/
Core.DialogBase = function(settings){
	var _temp = '<div class="dialog-box" style="display:none;z-index:1000000002">'+Core.Html.GetShadow()+'<div class="title-bar" rel="title_box"><span rel="base_title"></span><div class="title-handle"><a href="javascript:;" class="ha-close" btn="close">关闭</a></div></div><div rel="base_content"></div></div>';
	var _box,_cover,_timer, _self = this;
	var _settings = !settings? {}: settings;
	this.Main = Core.ACTIVE.GetMain();
	
	var create = function(win){
		if(!_self.warp){
			_self.warp = $(_temp);
			if(_settings.width){	//判断是否设置宽度
				_self.warp.width(_settings.width);
			}
			$(document.body).append(_self.warp);
			_self.warp.find("[btn]").mousedown(function(e){
				Core.Html.StopPropagation(e);
				return true;
			})
			_self.warp.find("[btn]").click(function(e){
				switch($(this).attr("btn")){
					case "close":
						_self.Close();
						break;
				}
				return false;
			});
			if(_settings.title){
				_self.warp.find("[rel='base_title']").html(_settings.title);
			}
			if(_settings.content){
				_self.warp.find("[rel='base_content']").append(_settings.content);
			}
			Util.Mouse.MoveBox({
				ClickBox: _self.warp.find("[rel='title_box']"),
				Box: _self.warp,
				Outer: _self.Main
			});
			if(_self.Initial){
				_self.Initial();
			}
		}
		if(!_cover){
			_cover = $('<div style="z-index: 1000000001; display: none;background: none repeat scroll 0 0 #fff;height: 100%;left: 0;position: absolute;top: 0;width: 100%;filter:alpha(opacity=0);-moz-opacity:0;opacity:0.0;"><div style="height:100%;width:100%;"></div></div>');
			$(document.body).append(_cover);
			_cover.bind("mousedown",function(){
				if(_timer){
					window.clearInterval(_timer);
				}
				_timer = window.setInterval(function(){
					if(_timer_index % 2){
						_self.warp && _self.warp.addClass(Core.CONFIG.ActiveClass);
					}
					else{
						_self.warp && _self.warp.removeClass(Core.CONFIG.ActiveClass);
					}
					_timer_index++;
					if(_timer_index > (Core.CONFIG.TwinkCount * 2 + 1)){
						_timer_index = 1;
						if(_timer){
							window.clearInterval(_timer);
						}
					}
				},Core.CONFIG.TwinkTime);
			});
		}
		Util.Layer.Center(_self.warp,{Main: win?win.warp:false});
	}
	
	var _timer_index = 1;
	
	
	this.Open = function(calback,win){
		create(win);
		if(calback){
			calback();
		}
		_cover.show();
		_self.warp.addClass(Core.CONFIG.ActiveClass).show();
	}
	
	this.Close = function(){
		_cover && _cover.hide().remove();
		_self.warp && _self.warp.hide().remove();
		_cover = false;
		_self.warp = false;
	}	
}

/*
	弹窗消息
*/
Core.Message = (function(){
	var _dialog;
	
	/*
	弹窗消息类
	*/
	var _MessageModel = function(){
		var _self = this, _initState = false, _callback, _openStatus = false,_dialog_type;
		
		var _content = $('<div>'+
                            '<div class="dialog-wrap" rel="content"></div>'+
                            '<div class="dialog-bottom"><div class="fr">'+
                                '<a href="javascript:;" class="button" btn="confirm">确定</a>'+
                                '<a href="javascript:;" class="button btn-gray" btn="cancel">取消</a>'+
                            '</div></div>'+
                        '<div>');
		
		Core.DialogBase.call(this,{content: _content, title: '信息提示'});	//继承dialog
		
		var setTitle = function(title){
			title && _self.warp.find("[rel='base_title']").html(title);
		}
		
		//初始化事件
		this.Initial = function(){
            
            
			if(!_initState){
                $(document).bind("keyup", function(e){
                    if(_openStatus){
                        if(e.keyCode == 13){
                            _content.find("[btn='confirm']").click();
                        }
                        else if(e.keyCode == 27){
                            switch(_dialog_type){
                                case 0:
                                    _content.find("[btn='confirm']").click();
                                    break;
                                case 1:
                                    _content.find("[btn='cancel']").click();
                                    break;
                            }

                        }
                    }
                })
			}
		}
		
        var _closeFun = this.Close;
        
        this.Close = function(){
            _closeFun();
            _openStatus = false;
        }
        
		this.Show = function(obj){
			_callback = false;
			_self.Open(function(){
                if(obj.confirm_link){
                    _content.find("[btn='confirm']").unbind("click").bind("click", function(){
                        _self.Close();
                        return true;
                    });
                    _content.find("[btn='confirm']").attr("href", obj.confirm_link).attr("target", "_blank");
                    _content.find("[btn='cancel']").unbind("click").bind("click",function(){
                        var r = true;
                        if(_callback){
                            r = _callback(false);
                        }
                        if(r === false){
                            return false;
                        }
                        _self.Close();
                        return false;
                    })
                }
                else{
                    var confrimBtn = _content.find("[btn='confirm']");
                    if(confrimBtn.attr("target")){
                        confrimBtn.removeAttr("target");
                        confrimBtn.attr("href", "javascript:;");
                    }
                    _content.find("[btn]").unbind("click").bind("click",function(){
                        var r = true;
                        if(_callback){
                            r = _callback($(this).attr("btn") == "confirm");
                        }
                        if(r === false){
                            return false;
                        }
                        _self.Close();
                        return false;
                    })
                }
                if(obj.confirm_text){
                    _content.find("[btn='confirm']").html(obj.confirm_text);
                }
                else{
                    _content.find("[btn='confirm']").html("确定");
                }
                
                if(obj.cancel_text){
                    _content.find("[btn='cancel']").html(obj.cancel_text);
                }
                else{
                    _content.find("[btn='cancel']").html("取消");
                }
				_callback = obj.callback;
				setTitle(obj.title);
				if(obj.dialog_type == undefined){
					obj.dialog_type = 0;
				}
				if(!obj.type){
					obj.type = "war"
				}
				var html_temp = '<div class="dialog-title"><i class="i-hint ico-{type}-l"></i>{text}</div>' + (obj.content?'<div class="dialog-content">{content}</div>' : "");
				var con = _content.find("[rel='content']");
				con.html(String.formatmodel(html_temp,obj));
				switch(obj.dialog_type){
					case 0:
						_content.find("[btn='cancel']").hide();
						break;
					case 1:
						_content.find("[btn='cancel']").show();
						break;
				}
                _dialog_type = obj.dialog_type;
                _openStatus = true;
			},obj.win);
            _content.find("[btn='confirm']").focus();
		}
	}
	
	var init = function(){
		if(!_dialog){
			_dialog = new _MessageModel();
		}
	}
	
	var _alertTimer;
	
	return {
		Confirm: function(obj){
			init();
			obj.dialog_type = 1;
			_dialog.Show(obj);
		},
		Alert: function(obj){
			init();
			obj.dialog_type = 0;
			_dialog.Show(obj);
			if(obj.timeout){
				_alertTimer = window.setTimeout(function(){
					Core.Message.Hide();
				}, obj.timeout);
			}
		},
		Hide: function(){
			if(_alertTimer){
				window.clearTimeout(_alertTimer);
			}
			if(_dialog){
				_dialog.Close();
			}
		}
	}
})();

/*
	浮动按钮
*/
Core.FloatMenu = (function(){
	var _menuData = {
		"right_file": {	//右键菜单设置
            "download": {text: "下载"},
//            "read": {text: "预览", ico:"preview"},
//            "shareto" : {text: "分享", ico: "share"},
			"renew": {text: "续期"},
			"cancelshare": {text: "取消分享"},
            "unloading": {text: "允许转存"},
            "cancelunloading": {text: "不允许转存"},
//            "privacy": {text: "加密", ico:"lock"},
			"move": {text: "移动"},
//            "cover": {text: "修改封面"},
            "edit_name": {text: "重命名", ico:"edit"},
//			"edit": {text: "备注", ico: "account"},
			"copylink": {text: "复制分享地址"},
			"delete": {text: "删除"}
            
		},
		"right_cate":{
			"add": {text: "新建文件夹", ico: "newdir"},
//			"share" : {text: "分享"},
			"cancelshare": {text: "取消分享"},
            "move": {text: "移动"},
//            "cover": {text: "修改封面"},
			"edit": {text: "重命名"},
//            "privacy": {text: "加密"},
			"delete": {text: "删除"}
		},
		"up_setting":{
			"flash": {text: "普通上传", ico: "done"},
			"ocx1": {text: "电信极速上传",ico: "done"},
			"ocx2": {text: "联通极速上传", ico: "done"}
		}
	}
	
	var _cacheDom = {};	//缓存标签对象 
	
	var _old_show_dom;
	
	var getMenu = function(obj){
		var dom = $('<div class="popup-menu" style="z-index:9999999; display:none;">' + Core.Html.GetShadow() + '</div>');
		var ul = $(document.createElement('ul'));
		for(var k in obj){
			var item = obj[k];
			var liTemp = '<li val="' + k + '"><a href="javascript:;"><i class="icon {type}"></i>{text}</a></li>';
			var type;
			if(item["ico"] == undefined){
				type = "ico-" + k;
			}
			else if(item["ico"] == ""){
				liTemp = '<li val="' + k + '"><a href="javascript:;">{text}</a></li>';
			}
			else{
				type = "ico-" + item["ico"]
			}
			var type = (item["ico"] == undefined)? ("ico-" + k) : (item["ico"] == ""? "" : "ico-" + item["ico"]);
			var li = $(String.formatmodel( liTemp, {type:type, text:item.text} ) );
			if(item.ischild || item.childs){
				li.find("a").append($('<b class="arrow">&raquo;</b>'));
			}
			if(item.childs){
				var childDom = getMenu(item.childs);
				//绑定事件
				li.bind("mouseover",{dom:li,childDom:childDom},function(e){
					if(_old_show_dom){
						_old_show_dom.hide();
						_old_show_dom = false;
					}
					var childDom = e.data.childDom;
					childDom.css({left: ""});
					childDom.show();
					var l = childDom.offset().left;
					if((l + childDom.width()) > $(window).width()){
						//l = l - childDom.width() - e.data.dom.width();
						childDom.css({left: -(childDom.width())});
					}
					_old_show_dom = childDom;
					$(this).attr("hide_state", "0");
				}).bind("mouseout",{childDom:childDom},function(e){
					var ele = $(this);
					ele.attr("hide_state", "1");
					var childDom = e.data.childDom;
					window.setTimeout(function(){
						if(ele.attr("hide_state") == "1"){
							childDom.hide();
						}
					},400);
				})
				
				childDom.bind("mouseover",{dom:li},function(e){
					e.data.dom.attr("hide_state", "0");
				}).bind("mouseout",{dom:li},function(e){
					var ele = e.data.dom;
					ele.attr("hide_state", "1");
					var childDom = $(this);
					window.setTimeout(function(){
						if(ele.attr("hide_state") == "1"){
							childDom.hide();
						}
					},400);
				})
				
				li.append(childDom);
			}
			ul.append(li);
		}
		dom.append(ul);
		dom.bind("contextmenu", function(e){return false;});
		return dom;
	}
	
	return {
		GetMenu: function(obj){
			return getMenu(obj);
		},
		Show: function(key,pos, setting){
			if(!_cacheDom[key] && _menuData[key]){
				_cacheDom[key] = getMenu(_menuData[key]);
				$(document.body).append(_cacheDom[key]);
			}
			
			if(_cacheDom[key]){
				if(pos){
					_cacheDom[key].css(pos);
				}
				_cacheDom[key].show();
				if(setting){
					var box = _cacheDom[key];
					if(setting.callback){
						box.find("[val]").bind("click", function(){
							setting.callback($(this).attr("val"));
							$(this).parent().find("i.ico-done").hide();
							$(this).find("i.ico-done").show();
							return false;
						}).find("i.ico-done").hide();
					}
					if(setting.select){
						var li = box.find("[val='"+setting.select+"']");
						if(li.find("i").hasClass("ico-done")){
							li.find("i").show();
						}
					}
				}
				return _cacheDom[key];
			}
			return false;
		},
		SetPosition: function(key,pos){
			if(_cacheDom[key]){
				if(pos){
					_cacheDom[key].css(pos);
				}
			}
		},
		SetRightBtnPos: function(dom, type, x, y, cutX, cutY){
			if(cutX == undefined){
				cutX = 0;
			}
			
			if(cutY == undefined){
				cutY = 0;
			}
			
			var desk = Core.ACTIVE.GetMain();
			if(x + dom.width() > desk.width()){
				x = x - dom.width() + cutX;
			}
			if(y + dom.height() > $(document).height()){
				y = y - dom.height() + cutY;
			}
			var pos = {top: y, left: x};
			Core.FloatMenu.SetPosition(type, pos);
			window.setTimeout(function(){
				dom.show();
			}, 100);
			
		},
		Hide: function(key){
			if(!_cacheDom[key]){
				_cacheDom[key].hide();
			}
		}
	}	
})();

//调试
Core.Debug = (function(){
	var _content, _model;
	
	var _class = function(content){
		Core.WindowBase.call(this, {content: content, title: "调试", min_title: "调试"});
	}
	
	return {
		write: function(msg){
			if(!Core.CONFIG.TUpDebugKey){return;}
			if(!_model){
				_content = $(document.createElement('textarea'));
				_content.css({width: "100%", height: "100%"});
				_model = new _class(_content);
				_model.Open();
			}
			_content.val(_content.val() + msg + "\n");
			
		}
	}
})();

/*
	IFRMAE窗口
*/
Core.Frame = function(url,obj){
	var _self = this;
	if(!obj){
		obj = {};
	}
	if(!obj.title){
		obj.title = "新窗口";
	}
	var _content = $('<div class="window-frame"><iframe src="" frameborder="0" rel="content"></iframe>'+(obj.is_has_flash?'<div class="app-back" rel="flash_op" style="display:none;"></div>':'')+'</div><div class="status-bar"></div>');
    
	//var _content = $('<div></div>');
    
	var _opcBoxTemp = '<div style="z-index: 9000000;background: none repeat scroll 0 0 black;height: 100%;left: 0;position: absolute;top: 0;width: 100%;filter:alpha(opacity=0.15);-moz-opacity:0;opacity:0;"></div>';
	var _opcBox;
	obj.content = _content;
    //obj.content = _iframe;
	Core.WindowBase.call(this, obj);
	
	var parentClose = _self.Close;
	var parentOpen = _self.Open;
	var parentActive = _self.Active;
	var parentDeActive = _self.DeActive;
	var _isClose = true;

	this.FrameSetting = obj;
    
    if(this.FrameSetting.is_has_flash != undefined && typeof this.FrameSetting.is_has_flash == "string"){
        this.FrameSetting.is_has_flash = Number(this.FrameSetting.is_has_flash);
    }

	this.Open = function(newUrl){
		parentOpen();
		/*if(!_content.find('[rel="content"]').length){
			_content.append(_iframe);
		}*/
		if(_isClose){
			_content.find("[rel='content']").attr("src",newUrl?newUrl : url);
			_isClose = false;
		}
		else{
			if(newUrl){
				_content.find("[rel='content']").attr("src",newUrl);
			}
		}
	}
	
	this.Close = function(){
		parentClose();
		_content.find("[rel='content']").attr("src","");
		if(_opcBox){
			_opcBox.remove();
			_opcBox = false;
		}
		_content.html("");
		_self.warp && _self.warp.remove();
		_self.warp = false;
		_isClose = true;
	}
	
	this.Active = function(zIndex){
		if(_opcBox){
			_opcBox.hide();
		}
		parentActive(zIndex);
		if(_self.FrameSetting.is_has_flash){
			_content.find("[rel='content']").css({height: "", width: ""});
			_content.find("[rel='flash_op']").hide();
		}
	}
	
	this.DeActive = function(zIndex){
		if(!_opcBox){
			_opcBox = $(_opcBoxTemp);
			_content.find("[rel='content']").before(_opcBox);
		}
		_opcBox.show();
		parentDeActive(zIndex);
		if(_self.FrameSetting.is_has_flash){
			_content.find("[rel='content']").css({height: "1px", width: "1px"});
			_content.find("[rel='flash_op']").show();
		}
	}
}

Core.Deving = (function(){
	var _win;
	return {
		Show: function(){
            
			if(!_win){
				var _content =  $('<div class="dialog-wrap developing-msg">该功能正在紧张开发中，敬请期待！</div>'+
                    '    <div class="dialog-bottom"><div class="fr"> <a href="javascript:;" class="button" btn="confirm"><span class="btn-con">确定</span></a></div></div>');
				_win = new Core.DialogBase({
					title: '功能开发中，敬请期待',
					content: _content
				})
			}
			
			_win.Open(function(){
				_win.warp.find('[btn="confirm"]').click(function(){
					_win.Close();
					return false;
				})
			});
		}
	}
})();

Core.VIPNotice = (function(){
    var _win, _spaceWin;
    
    var create = function(){
        if(!_win){
            var url = '?ct=vip_notice';
            if(Core.FilePermission.VipExp()){
                url += '&ac=exp';
            }
            
            var _content =  $('<iframe style="width:100%; height:470px; background:#fff;" frameborder=0 src="'+url+'"></iframe>');
            _win = new Core.DialogBase({
                title: 'VIP贵宾提示',
                content: _content,
                width:680
            });
        }
    }
    
    return {
        Upgrade: function(){
            create();
            _win.Open();
        },
        NotSpace: function(){
            if(Core.FilePermission.Vip()) return;
            if(Core.FilePermission.VipExp()) return;
            var notspace_cook = Util.Cookie.get('not_space_cook');
            //notspace_cook = false;
            if(!notspace_cook){
                if(!_spaceWin){
                    var _content = $('<div class="popup-chicken">' +
                                        '<div class="checken-content">' +
                                            '<h3>糟糕，您的空间就快用完啦！</h3>' +
                                            '<p>建议您升级成为VIP贵宾，立即扩容空间！<br/>' +
                                            'VIP服务说明：额外扩容50GB或115GB超大云盘+超长分享期限+超大同步盘+1.5G超大文件上传+文件加密码分享...</p>' +
                                            '<p>'+
                                                '<a href="'+Core.CONFIG.Path.VIP_ORDER+'/?p=no_space" target="_blank" class="btn btn-vip">马上成为VIP会员</a> '+
                                                '<a href="'+Core.CONFIG.Path.VIP+'/space/?p=no_space" target="_blank" class="btn btn-space">扩容纯空间</a>'+
                                            '</p>' +
                                        '</div>' +
                                    '</div>');
                    _spaceWin = new Core.DialogBase({
                        title: "糟糕，您的空间就快用完啦！",
                        width:530,
                        content: _content
                    });
                }
                _spaceWin.Open();
                Util.Cookie.set('not_space_cook', "1", 24);
            }
        }
    }
})()
